<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>档案信息管理</title>
<link rel="stylesheet" type="text/css"
	href="../assets/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"
	href="../assets/admin/css/admin.css" />
</head>

<body>
	<div class="page-content-wrap" id="achivesManage">
		<h5
			style="text-align: center; font-size: 20px; line-height: 25px; color: #666">档案信息管理</h5>
		<hr>
		<form class="layui-form" action="">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="empName" 
						autocomplete="off" id="empName" class="layui-input" placeholder="请输入姓名">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">性別</label>
				<div class="layui-input-block">
					<select name="empSex" id="empSex">
						<option value="">请选择性别</option>
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
				</div>
			</div>
				<div class="layui-inline">
				<label class="layui-form-label">学历</label>
				<div class="layui-input-block">
					<select name="education" id="education">
						<option value="">请选择学历</option>
						<option value="1">大专</option>
						<option value="2">本科</option>
						<option value="3">硕士</option>
						<option value="4">博士</option>
					</select>
				</div>
			</div>
			<button class="layui-btn layui-btn-normal"
				lay-submit lay-filter="search" >搜索</button>
			</div>
		
		
		</form>
		
		<div class="layui-form-item">
			<button class="layui-btn layui-btn-small site-demo-active"
					data-type="achievesAdd">
					<i class="layui-icon">&#xe654;</i>
				</button>
			<table class="layui-hide" id="achives" lay-filter="achives"></table>
			
		</div>
</div>

		<hr></hr>
		<h5 style="text-align: center;">@2019.HR</h5>
	</div>
	<script src="../assets/admin/layui/layui.all.js" type="text/javascript"
		charset="utf-8"></script>
	<script>
		layui.use('table', function() {
			var form = layui.form;
			var $ = layui.jquery;
			var table = layui.table;

			table.render({
				id:'achivesList',
				elem : '#achives',
				url : '/achives/getAll',
				title : '用户数据表',
				totalRow : true,
				cols : [ [
					
						{
							field : 'empId',
							title : '档案编号',
							width: 120
						},
						{
							field : 'empName',
							title : '姓名',
							width: 120
						},
						{
							field : 'empSex',
							title : '性别',
							width: 120
						},
						{
							field : 'departName',
							title : '所属部门',
							width: 120
						},
						
						{
							field : 'empAddress',
							title : '地址',
							width: 200
						},
						{
							field : 'empBirth',
							title : '出生年月',
							width: 200,
							templet : function(res) {
								var empBirth=res.empBirth.substring(0,7);
								return '<em>'+empBirth+'</em>'
							}
						},
						{
							field : 'empCard',
							title : '身份证号',
							width: 200
						},
						{
							field : 'entryTime',
							title : '入职时间',
							width: 120,
							templet : function(res) {
								var entryTime=res.entryTime.substring(0,10);
								return '<em>'+entryTime+'</em>'
							}
						},
						{
							field : 'empTitles',
							title : '职称',
							width: 200
						},
						{
							field : 'mobile',
							title : '手机号',
							width: 200
						},
						{
							field : 'graduationTime',
							title : '毕业时间',
							width: 200,
							templet : function(res) {
								var graduationTime=res.graduationTime.substring(0,7);
								return '<em>'+graduationTime+'</em>'
							}
						},
						{
							field : 'graduationShcool',
							title : '毕业院校',
							width: 200
							
						},
						{
							field : 'education',
							title : '学历',
							width: 200,
							templet : function(res) {
								var education=res.education;
								if(1==education){
									return '<em>大专</em>'
								}
								if(2==education){
									return '<em>本科</em>'
								}
								if(3==education){
									return '<em>硕士</em>'
								}
								if(4==education){
									return '<em>博士</em>'
								}
							}
						},
						{
							field : 'empStatus',
							title : '状态',
							width: 200,
							templet : function(res) {
								var empStatus=res.empStatus;
								if(1==empStatus){
									return '<em>在职</em>'
								}
								if(2==empStatus){
									return '<em style="color:red">离职</em>'
								}
							}
						},
						{
							fixed : 'right',
							title : '操作',
							width : 150,
							templet : function(res) {
								var empStatus=res.empStatus;
								if(1==empStatus){
									return '<a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">离职</a>'
								}
								if(2==empStatus){
									return '无'
								}
							}
						} ] ],
				page : true
			});
			//事件绑定
			var active = {
					achievesAdd : function() {
						layer.open({
						      type: 2,
						      title: '添加档案',
						      shadeClose: true,
						      shade: false,
						   /*    maxmin: true,  *///开启最大化最小化按钮
						      area: ['800px', '500px'],
						      content: '/achives/achives-add.html'
						    });
					
					}
			};
			//表格事件绑定

		table.on('tool(achives)', function(obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				edit(data);
			} else if (obj.event === 'del') {
				layer.confirm('真的改为离职状态吗', function(index) {
					del(data,index);
				});
			}
		});
		form.on('submit(search)',
				function(data) {
					var str = JSON.stringify(data.field)
					var param = JSON.parse(str);
					table.reload('achivesList',{
						method: 'POST'
					 , where: param,page: {
					    curr: 1 //重新从第 1 页开始
					  }
					});
				return false;
			
			});	
		function edit(data){
			var editFrom = layui.layer.open({
		        title : "编辑档案信息",
		        type : 2,
		        content : "/achives/achives-edit.html",//弹出层页面
		        area: ['800px', '500px'],
		        success : function(layero, index){
		            var body = layui.layer.getChildFrame('body', index);
		            
		            //获取窗口对象
		            var iframeWindow = layero.find('iframe')[0].contentWindow;
		            iframeWindow.layui.form.render('select');
		            iframeWindow.layui.form.render();
		            
		            body.find("#empId").val(data.empId);
		            body.find("#empName").val(data.empName);
		            body.find("#empAddress").val(data.empAddress);
		            body.find("#empSex option[value="+data.empSex+"]").attr("selected","selected");
		            
		            body.find("#empBirth").val(data.empBirth.substring(0,10));
		            body.find("#empCard").val(data.empCard);
		            body.find("#entryTime").val(data.entryTime.substring(0,10));
		            body.find("#empTitles").val(data.empTitles);
		            
		            body.find("#mobile").val(data.mobile);
		            body.find("#graduationTime").val(data.graduationTime.substring(0,10));
		            body.find("#education").val(data.education);
		            body.find("#graduationShcool").val(data.graduationShcool);
		         	var empDepart=data.empDepart;
		            
		          /*   body.find("#empDepart option[value="+data.empDepart+"]").attr("selected","selected"); */
					//编辑界面下拉框加载

		                  //加载部门选择下拉框
			  $.ajax({
	           //几个参数需要注意一下
	               type: "POST",//方法类型
	               dataType: "json",//预期服务器返回的数据类型
	               url: "/depart/getAlldepartSelect",//url
	               data: {},
	               success: function (result) {
	               	if (result.code == "0") {
	               		var data=result.data;
	               		body.find("#empDepart").html('<option value="">请输入/选择部门</option>');
	               		if(data.length>0){
	               			for(i=0;i<data.length;i++){
	               				var temp=data[i];
	               				if(empDepart==temp.departId){
		               				body.find("#empDepart").append('<option value="'+temp.departId+' " selected="selected">'+temp.departName+'</option>');

	               				}else{
		               				body.find("#empDepart").append('<option value="'+temp.departId+' ">'+temp.departName+'</option>');
	               				}
	               			}
	               		 iframeWindow.layui.form.render('select');
	               		}
	                 }else{
	                 	layer.msg('加载部门下拉框失败', {
	                         icon: 5
	                     });
	                 }
	               },
	               error : function() {
	               	layer.msg('加载部门下拉框失败', {
	                       icon: 5
	                   });
	               }
	           });
		            iframeWindow.layui.form.render();
		            iframeWindow.layui.form.render('select');
		        }});
		}
		
		function del(data,index){
			var param={
					"empId":data.empId,
					"empStatus":2
			};
			 $.ajax({
	                //几个参数需要注意一下
	                    type: "POST",//方法类型
	                    dataType: "json",//预期服务器返回的数据类型
	                    url: "/achives/updateAchivesStatus",//url
	                    data: param,
	                    success: function (result) {
	                    	if (result.code == "0") {
	                    			layer.close(index);
	                    			layer.msg("状态修改成功");
	                    			table.reload('achivesList');
			                    }else{
			                    	layer.msg(result.msg);
			                    }
	                    },
	                    error : function() {
	                    	layer.msg('服务器错误', {
	                            icon: 5
	                        });
	                    }
	                });
		}
		
		$('#achivesManage .layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

	});
	</script>
</body>

</html>